import {
  Body,
  Controller,
  Get,
  Post,
  Query,
  Request,
  UseGuards,
} from "@nestjs/common";
import { ApiOperation, ApiTags } from "@nestjs/swagger";
import {
  CartDto,
  CollectDto,
  DelCollectDto,
  GetCartDto,
  GetCollectDto,
} from "../dto/operate.dto";
import { WeappOperateService } from "./operate.service";
import { RolesGuard } from "/@/logical/adminModule/auth/roles.guard";

@ApiTags("weapp-operate")
@Controller("operate")
@UseGuards(RolesGuard)
export class WeappOperateController {
  constructor(private readonly operateService: WeappOperateService) {
    //
  }

  @Get("getSwiperList")
  @ApiOperation({ summary: "获取轮播" })
  async getGoodsTypeByPid(): Promise<any> {
    return this.operateService.getSwiperList();
  }

  // 收藏相关
  @Get("getCollectList")
  @ApiOperation({ summary: "获取用户收藏商品" })
  async getCollectList(
    @Query() query: GetCollectDto,
    @Request() request,
  ): Promise<any> {
    return this.operateService.getCollectList(query, request.user);
  }

  @Post("addCollect")
  @ApiOperation({ summary: "用户添加收藏商品" })
  async addCollect(
    @Body() params: CollectDto,
    @Request() request,
  ): Promise<string> {
    return this.operateService.addCollect(params, request.user);
  }

  @Post("delCollect")
  @ApiOperation({ summary: "用户删除收藏商品" })
  async delCollect(
    @Body() params: CollectDto,
    @Request() request,
  ): Promise<string> {
    return this.operateService.delCollect(params, request.user);
  }

  // 购物车
  @Get("getCartList")
  @ApiOperation({ summary: "获取用户购物车列表" })
  async getCartList(
    @Query() query: GetCartDto,
    @Request() request,
  ): Promise<any> {
    return this.operateService.getCartList(query, request.user);
  }

  @Post("changeCart")
  @ApiOperation({ summary: "用户添加、增加数量、删除 购物车" })
  async changeCart(
    @Body() params: CartDto,
    @Request() request,
  ): Promise<string> {
    return this.operateService.changeCart(params, request.user);
  }
}
